﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Modeling;

namespace DSLFactory.VSCTDesigner
{
    //partial class GroupSerializerBase
    //{
    //    protected static void CustomReadChildElements(SerializationContext serializationContext, Group element, global::System.Xml.XmlReader reader)
    //    {
    //        ReadChildElements(serializationContext, element, reader);
    //    }

    //    [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Generated code.")]
    //    [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Generated code.")]
    //    protected static void CustomWriteChildElements(SerializationContext serializationContext, Group element, global::System.Xml.XmlWriter writer)
    //    {
    //        WriteChildElements(serializationContext, element, writer);
    //    }
    //}

    partial class GroupSerializer
    {
        #region CommandFlags
        protected override void ReadElements(SerializationContext serializationContext, ModelElement element, global::System.Xml.XmlReader reader)
        {
            base.ReadElements(serializationContext, element, reader);

            Group instanceOfCommandWithIcon = element as Group;
            global::System.Diagnostics.Debug.Assert(instanceOfCommandWithIcon != null, "Expecting an instance of CommandWithIcon!");

            // Read properties serialized as nested XML elements.
            if( !serializationContext.Result.Failed )
                CustomReadPropertiesFromElements(serializationContext, instanceOfCommandWithIcon, reader);
        }

        /// <summary>
        /// Reads the properties from elements.
        /// </summary>
        /// <param name="serializationContext">The serialization context.</param>
        /// <param name="element">The element.</param>
        /// <param name="reader">The reader.</param>
        /// <remarks>
        /// </remarks>
        protected void CustomReadPropertiesFromElements(Microsoft.VisualStudio.Modeling.SerializationContext serializationContext, Group element, System.Xml.XmlReader reader)
        {
            while( !serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element )
            {
                switch( reader.LocalName )
                {
                    case "CommandFlag":	// CommandFlag
                        if( reader.IsEmptyElement )
                        {	// No serialized value, must be default one.
                            SerializationUtilities.Skip(reader);  // Skip this tag.
                        }
                        else
                        {
                            string strCommandFlag = reader.ReadInnerXml();
                            if( strCommandFlag == "Dynamic" )
                                element.Dynamic = true;

                            SerializationUtilities.SkipToNextElement(reader);
                        }
                        break;
                    default:
                        return;  // Don't know this element.
                }
            }
        }

        protected override void WriteElements(SerializationContext serializationContext, ModelElement element, global::System.Xml.XmlWriter writer)
        {
            base.WriteElements(serializationContext, element, writer);

            Group instance = element as Group;
            global::System.Diagnostics.Debug.Assert(instance != null, "Expecting an instance of CommandWithIcon!");

            // Write properties serialized as nested XML elements.
            if( !serializationContext.Result.Failed )
                CustomWritePropertiesAsElements(serializationContext, instance, writer);
        }

        /// <summary>
        /// Writes the properties as elements.
        /// </summary>
        /// <param name="serializationContext">The serialization context.</param>
        /// <param name="element">The element.</param>
        /// <param name="writer">The writer.</param>
        /// <remarks>
        /// </remarks>
        protected void CustomWritePropertiesAsElements(Microsoft.VisualStudio.Modeling.SerializationContext serializationContext, Group element, System.Xml.XmlWriter writer)
        {
            // CommandFlag
            if( !serializationContext.Result.Failed )
            {
                if( element.Dynamic )
                    writer.WriteElementString("CommandFlag", "Dynamic");
            }
        }
        #endregion
    }
}
